package com.yourenbang.lingyun.transaction.web.service.impl.fund;

import com.yourenbang.lingyun.core.exception.BizRuntimeException;
import com.yourenbang.lingyun.core.util.KLog;
import com.yourenbang.lingyun.transaction.mapper.TransactionFundAccountChangePlanMapper;
import com.yourenbang.lingyun.transaction.web.domain.po.FundAccountChangePlan;
import com.yourenbang.lingyun.transaction.web.service.fund.FundAccountChangePlanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import static com.yourenbang.lingyun.constants.BizCodeMessages.DB_WRITE_ERR;

@Service
@Slf4j
public class FundAccountChangePlanServiceImpl implements FundAccountChangePlanService {

    @Autowired
    private TransactionFundAccountChangePlanMapper fundAccountChangePlanMapper;

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void insertFundAccountChangePlan(FundAccountChangePlan plan) {

        int insert = fundAccountChangePlanMapper.insert(plan);
        KLog.info("插入变动记录{},结果:{}",plan,insert);
        if (insert != 1) {
            KLog.error("创建变动记录失败");
            throw new BizRuntimeException(DB_WRITE_ERR, "创建变动记录失败");
        }
    }
    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void updateFundAccountChangePlan(FundAccountChangePlan plan){

        int i = fundAccountChangePlanMapper.updateById(plan);
        if (i != 1) {
            KLog.error("更新变动失败");
            throw new BizRuntimeException(DB_WRITE_ERR, "创建变动记录失败");
        }
    }
}
